<div id="importTicketPage">
<script type="text/javascript" src='{$base_dir}modules/dept_pharmacy/js/AJAX_EwhImport.js'></script>
<script type="text/javascript" src='{$base_dir}modules/dept_pharmacy/js/AJAX_DrugMaterialAutoComplete.js'></script>

<script type="text/javascript">
var itemType = "{$selectedPhaItemType}";
{assign var="count" value=1}
var dateFormatPart0 = "{$datePart_0}";
var dateFormatPart1 = "{$datePart_1}";
var dateFormatPart2 = "{$datePart_2}";
{literal}
    $(document).ready(function() {
    	checkAndDisableItemTypeSel();
    	addDatePicker("#datedd",'#datemm','#dateyyyy',false,false,true);
    	
    	$('select#selItemType').bind('change', function() { 
    		$('#inputDMName').flushCache();  		
    		
    	});  
        
        $('#inputDMName').autocomplete("../AutoSuggest/DrugMaterialAutoSuggestAjax?set_ajax_view" 
                ,
	        	{
		            width: 300,
		            multiple: true,
		            matchContains: true,	            
		            autoFill:true,
		            max: 10,		            
		            extraParams: {
                	enumItemType: function() {
                	    return $('select#selItemType').val(); 
                	    }
                    }
	            }
        );
        
        $("#inputDMName").result(function(event, data, formatted) {
            if (data != null) {
	            $(this).val(data[0]);
	            var hidden = $('input#inputDMNameHidden');
	            hidden.val(data[1]);
	            $('input#inputDMLot').select();
	            //fill auto fill field	            
	            $('span#inputDMUnit').html(data[2]);    
	            $('#inputDMUnitHidden').val(data[3]);	            
	            	            
            } 
            
        });                

        $('input#createImTicketBnt').bind('click', function() { 
            $('#inputDMName').flushCache(); 
            //createNewImTicket();
            resetImportTicketForm();        
            
        }); 
        /*

        $('#dateExpdd').bind('keydown', function(event){
        	if ($(this).val().length >=2) {           	
            	
            	if (isEraserKey(event) == false) {
            		   $('#dateExpmm').select();
            	}                
            }
        });
        $('#dateExpmm').bind('keydown', function(event){
        	if ($(this).val().length >=2) {
                if (isEraserKey(event) == false) {
                       $('#dateExpyyyy').select();
                }                
            }
        });
        $('#dateExpyyyy').bind('keydown', function(event){
        	if ($(this).val().length >=4) {
                if (isEraserKey(event) == false) {
                       $('#inputDMUnitPrice').select();
                }                
            }
        });

        $('#inputDMQty').bind('keydown', function(event){
            if (isEraserKey(event) == false) {                
            	if ($(this).val().length >= 5) {
                   return false;
            	}
            }             
            
        });
        */

        $('#saveImTicketBnt').bind('click', function () {
        	saveImTicket();
            
        });
        $('#deleteImTicketBnt').bind('click', function () {
        	var imTicketId = $("input#imticketId").val();
        	if (imTicketId != null && $.trim(imTicketId) != '') {
        		deleteImTicketCP(imTicketId);
        	}
        });

        
        
        var imTicketId = $("input#imticketId").val();
        if (imTicketId != null && $.trim(imTicketId) != '') { 
            enableAdding(true);
        } else {
        	enableAdding(false);
        }
        $("input[name=createDate]")[0].select();
        
        
    });

    

{/literal}
</script>
<div class="form_container">
<input type="button" id="createImTicketBnt" value="{translate}Create new import ticket{/translate}" >
<br>
<span id='statusMessageImTicket' style="font-style:italic; color: red;">&nbsp;</span>
<br>
<table cellspacing="0" cellpadding="0" id="imTicketMetaTable" class="inline">
    <tbody>
        <tr>
            <td class="label" style="width: 100px;">{translate}Ticket code{/translate}</td>
            <td class="form_input" style="width: 250px;">
	            <span id='imticketCodeText'></span>
                <input type="hidden" id="imticketCode" value="{$imticketCode}">
                <input type="hidden" id="imticketId" value="{$imticketId}">
            </td>
            <td class="label" style="width: 100px;">{translate}Provider{/translate}</td>
            <td class="form_input" style="width: 250px;"> 
	            <select style="width: 100%;" tabindex="5" id="selProvider">
	               <option value="" style="text-align: center;">{translate}--Select provider--{/translate}</option>
	               {html_options options=$providers  selected=$selectedProvider}
	            </select>
            </td>
        </tr>
        <tr>
            <td class="label">{translate}Date{/translate}</td>
            <td class="form_input">
                <input tabindex="1" onkeypress="return allowEnterIntegerNum(event,true)" name="createDate" id="date{$datePart_0}" type="text" value="{$datePart[0]}" style="width: 30px;">
                <input tabindex="2" onkeypress="return allowEnterIntegerNum(event,true)" name="createDate" id="date{$datePart_1}" type="text" value="{$datePart[1]}" style="width: 30px;">
                <input tabindex="3" onkeypress="return allowEnterIntegerNum(event,true)" name="createDate" id="date{$datePart_2}" type="text" value="{$datePart[2]}" style="width: 56px;">
                <br /><span class="label" style="width: 21px; color: #AAA;">({$datePart_0}-{$datePart_1}-{$datePart_2})</span>
            </td>
            <td class="label">{translate}Vat{/translate}%</td>
            <td class="form_input"> 
            <select style="width: 70px;" tabindex="6" id="selVat">
                {html_options options=$vatList  selected=$defaultVat}
            </select>
            </td>
        </tr>
        <tr>
            <td class="label">{translate}User input{/translate}</td>
            <td class="form_input">{$loginUser.userName}<input type="hidden" id="inputUserId" value="{$loginUser.userId}"> </td>
            <td class="label">{translate}Note{/translate}</td>
            <td class="form_input"><input type="text" value="" style="width: 97%;" tabindex="7" id="note"/></td>
        </tr>
        <tr class="last">
            <td class="label">{translate}Type{/translate}</td>
            <td class="form_input">
              <select style="width: 145px;" tabindex="4" id="selItemType">
                   {html_options options=$phaItemTypes  selected=$selectedPhaItemType}
                </select>
            </td>
            <td class="label">&nbsp;</td>
            <td class="form_input">&nbsp;</td>
        </tr>
    </tbody>
</table> 
<div align="right" style="width: 100%;">
<span id='savingStatusMessage'></span>
<input tabindex="8" type="button" id="saveImTicketBnt" value="{translate}Save{/translate}" >
&nbsp;
<input type="button" id="deleteImTicketBnt" value="{translate}Delete{/translate}">
</div>   
</div>
<div style="margin-top: 10px;" class="lab_grid">
<br>
<span id='statusMessage' style="font-style:italic; color: red;">&nbsp;</span>
<br>
<div class="h_div">
<table cellspacing="0" cellpadding="0">
	<thead>
		<tr>
			<th style="width: 30px;">{translate}Order number{/translate}</th>
			<th style="width: 200px;">{translate}Name{/translate}</th>
			<th style="width: 75px;">{translate}Lot{/translate}</th>
			<th style="width: 75px;">{translate}Quantity{/translate}</th>
			<th style="width: 75px;">{translate}Unit{/translate}</th>
			<th style="width: 145px;">{translate}Expired date{/translate}</th>
			<th style="width: 100px;">{translate}Unit price{/translate}</th>
			<th style="width: 100px;">{translate}Price{/translate}</th>
			<th style="border-right: none;" class="last">&nbsp;&nbsp;&nbsp;</th>			
		</tr>
	</thead>
</table>
</div>
<div >
<div class="b_div">
<table id="inputDrugMaterialTable" cellspacing="0" cellpadding="0" border="0" >
	<tbody>	
	   <tr>
            <td style="width: 30px;">&nbsp;</td>
            <td style="width: 200px;">
            <input tabindex="9" id="inputDMName" type="text" style="width: 180px;"/>
            <input id="inputDMNameHidden" type="hidden" value=""/>
            </td>
            <td style="width: 75px;"><input tabindex="10" id="inputDMLot" type="text" style="width: 60px;"/></td>
            <td style="width: 75px;"><input tabindex="11" onkeypress="return allowEnterIntegerNum(event,true)" id="inputDMQty"  type="text" style="width: 60px;"/></td>
            <td style="width: 75px;">
	            <span id="inputDMUnit"></span>
	            <input id="inputDMUnitHidden" type="hidden" style="width: 60px;" value=""/>
            </td>
            <td style="width: 145px;">                
                <input tabindex="12" onkeypress="return allowEnterIntegerNum(event,true)" name="dateExp" id="dateExp{$datePart_0}" type="text" value="" style="width: 30px;">
                <input tabindex="13" onkeypress="return allowEnterIntegerNum(event,true)" name="dateExp" id="dateExp{$datePart_1}" type="text" value="" style="width: 30px;">
                <input tabindex="14" onkeypress="return allowEnterIntegerNum(event,true)" name="dateExp" id="dateExp{$datePart_2}" type="text" value="" style="width: 56px;">
            </td>
            <td style="width: 100px;"><input tabindex="15" onkeypress="return allowEnterIntegerNum(event,true)" id="inputDMUnitPrice" type="text" style="width: 90px;"/></td>
            <td style="width: 100px;">&nbsp;</td>
            <td style="border-right: none;"><div id="addDrugMaterialBtn" style="display: none;"><a tabindex="17" href="javascript:addDrugMaterialRow();" style="cursor: pointer;"><img alt="" src="../images/add_small.png"></a></div> </td>           
        </tr>	
	</tbody>
</table>
</div>
<br>
<input id= 'addedDMCount' value={$count} type="hidden">
<div class="b_div" style="height: 250px; border-top: 1px solid #DDDDDD;" >
<table id="addedDrugMaterialTable" cellspacing="0" cellpadding="0" border="0" >
    <tbody>
    </tbody>
</table>
</div>
</div>
</div>
<div id="phaImportLoaderDiv" style="display: none; position: fixed; top: 0px; left: 0px; height: 100%; width: 100%; z-index: 1000">
    <div style="overflow: hidden; background-color: #000; position: absolute; top: 0px; left: 0px; height: 100%; width: 100%; opacity: 0.2;">
    </div>
    <div style='padding: 6px 0px 0px 6px; position: absolute; top: 50%; left: 50%; width: 40px; height: 40px; background: #F5F5F5; border: 3px solid #CCC; margin-left: -20px; margin-top: -30px;'>
        <img src="{$base_uri}/images/ajax-loader.gif"/>
    </div>
</div>
</div>
